package com.xiongmm.stream.sink;

import com.xiongmm.stream.database.DataManipulation;
import com.xiongmm.stream.domain.InstanceInfoCmdVo;
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @author: XiongMM
 * @date: 2019/5/30 17:10
 * @description:
 */
public class SinkInfoCmdToMySQL extends RichSinkFunction<List<InstanceInfoCmdVo>> {

    private static final Logger LOGGER = LoggerFactory.getLogger(SinkInfoCmdToMySQL.class);

    @Override
    public void invoke(List<InstanceInfoCmdVo> infoCmdVos, Context context) throws Exception {
        for (InstanceInfoCmdVo infoCmdVo : infoCmdVos) {
            try {
                DataManipulation.insertInstanceCmd(infoCmdVo);
            } catch (Exception ex) {
                LOGGER.error("SinkInfoCmdToMySQL.execute ------> 插入cmd 失败", ex);
            }
        }
    }
}
